/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2011 All Rights Reserved.
 */
package com.alipay.supergw.common.dal.share_supergw.auto.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.alibaba.common.lang.Paginator;
import com.alipay.supergw.common.dal.share_supergw.auto.daointerface.OutResponseCodeDAO;
import com.alipay.supergw.common.dal.share_supergw.auto.dataobject.OutResponseCodeDO;
import com.iwallet.biz.common.util.PageList;

/**
 * An ibatis based implementation of dao interface <tt>com.alipay.supergw.common.dal.share_supergw.auto.daointerface.OutResponseCodeDAO</tt>.
 *
 * This file is generated by <tt>supergw-dalgen</tt>, a DAL (Data Access Layer)
 * code generation utility specially developed for <tt>supergw</tt> project.
 * 
 * PLEASE DO NOT MODIFY THIS FILE MANUALLY, or else your modification may
 * be OVERWRITTEN by someone else. To modify the file, you should go to 
 * directory <tt>(project-home)/dalgen</tt>, and 
 * find the corresponding configuration file (<tt>tables/sgw_out_response_code.xml</tt>). 
 * Modify the configuration file according to your needs, then run <tt>supergw-dalgen</tt> 
 * to generate this file.
 */
public class IbatisOutResponseCodeDAO extends SqlMapClientDaoSupport implements OutResponseCodeDAO {

    /**
     *  Query DB table <tt>sgw_out_response_code</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select channel_system_id, response_code, trans_result, response_message, inner_message, gmt_create, gmt_modified from sgw_out_response_code</tt>
     *
     *	@return List<OutResponseCodeDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings("unchecked")
    public List<OutResponseCodeDO> loadAll() throws DataAccessException {

        return getSqlMapClientTemplate().queryForList("MS-OUT-RESPONSE-CODE-LOAD-ALL", null);

    }

    /**
     *  Insert one <tt>OutResponseCodeDO</tt> object to DB table <tt>sgw_out_response_code</tt>, return primary key
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>insert into SGW_OUT_RESPONSE_CODE(CHANNEL_SYSTEM_ID,RESPONSE_CODE,TRANS_RESULT,RESPONSE_MESSAGE,INNER_MESSAGE,GMT_CREATE,GMT_MODIFIED) values (?, ?, ?, ?, ?, sysdate, sysdate)</tt>
     *
     *	@param outResponseCode
     *	@return String
     *	@throws DataAccessException
     */
    public String insert(OutResponseCodeDO outResponseCode) throws DataAccessException {
        if (outResponseCode == null) {
            throw new IllegalArgumentException("Can't insert a null data object into db.");
        }

        getSqlMapClientTemplate().insert("MS-OUT-RESPONSE-CODE-INSERT", outResponseCode);

        return outResponseCode.getResponseCode();
    }

    /**
     *  Query DB table <tt>sgw_out_response_code</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select CHANNEL_SYSTEM_ID, RESPONSE_CODE, TRANS_RESULT, RESPONSE_MESSAGE, INNER_MESSAGE, GMT_CREATE, GMT_MODIFIED from SGW_OUT_RESPONSE_CODE where (CHANNEL_SYSTEM_ID = ?)</tt>
     *
     *	@param channelSystemId
     *	@return List<OutResponseCodeDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings("unchecked")
    public List<OutResponseCodeDO> selectByChannelSystem(String channelSystemId)
                                                                                throws DataAccessException {

        return getSqlMapClientTemplate().queryForList(
            "MS-OUT-RESPONSE-CODE-SELECT-BY-CHANNEL-SYSTEM", channelSystemId);

    }

    /**
     *  Query DB table <tt>sgw_out_response_code</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select CHANNEL_SYSTEM_ID, RESPONSE_CODE, TRANS_RESULT, RESPONSE_MESSAGE, INNER_MESSAGE, GMT_CREATE, GMT_MODIFIED from SGW_OUT_RESPONSE_CODE where ((CHANNEL_SYSTEM_ID = ?) AND (RESPONSE_CODE = ?) AND (rownum <= 50)) order by GMT_CREATE ASC</tt>
     *
     *	@param channelSystemId
     *	@param responseCode
     *	@return List<OutResponseCodeDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public List<OutResponseCodeDO> select(String channelSystemId, String responseCode)
                                                                                      throws DataAccessException {
        Map param = new HashMap();

        param.put("channelSystemId", channelSystemId);
        param.put("responseCode", responseCode);

        return getSqlMapClientTemplate().queryForList("MS-OUT-RESPONSE-CODE-SELECT", param);

    }

    /**
     *  Update DB table <tt>sgw_out_response_code</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>update SGW_OUT_RESPONSE_CODE set TRANS_RESULT=?, RESPONSE_MESSAGE=?, INNER_MESSAGE=?, GMT_MODIFIED=sysdate where ((CHANNEL_SYSTEM_ID = ?) AND (RESPONSE_CODE = ?))</tt>
     *
     *	@param transResult
     *	@param responseMessage
     *	@param innerMessage
     *	@param channelSystemId
     *	@param responseCode
     *	@return int
     *	@throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public int update(String transResult, String responseMessage, String innerMessage,
                      String channelSystemId, String responseCode) throws DataAccessException {
        Map param = new HashMap();

        param.put("transResult", transResult);
        param.put("responseMessage", responseMessage);
        param.put("innerMessage", innerMessage);
        param.put("channelSystemId", channelSystemId);
        param.put("responseCode", responseCode);

        return getSqlMapClientTemplate().update("MS-OUT-RESPONSE-CODE-UPDATE", param);
    }

    /**
     *  Delete records from DB table <tt>sgw_out_response_code</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>delete from SGW_OUT_RESPONSE_CODE where ((CHANNEL_SYSTEM_ID = ?) AND (RESPONSE_CODE = ?))</tt>
     *
     *	@param channelSystemId
     *	@param responseCode
     *	@return int
     *	@throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public int delete(String channelSystemId, String responseCode) throws DataAccessException {
        Map param = new HashMap();

        param.put("channelSystemId", channelSystemId);
        param.put("responseCode", responseCode);

        return getSqlMapClientTemplate().delete("MS-OUT-RESPONSE-CODE-DELETE", param);
    }

    /**
     *  Update DB table <tt>sgw_out_response_code</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select CHANNEL_SYSTEM_ID, RESPONSE_CODE, TRANS_RESULT, RESPONSE_MESSAGE, INNER_MESSAGE, GMT_CREATE, GMT_MODIFIED from SGW_OUT_RESPONSE_CODE</tt>
     *
     *  @param channelSystemId
     *  @param responseCode
     *  @param pageSize
     *  @param pageNum
     *  @return PageList
     *  @throws DataAccessException
     */
    @SuppressWarnings( { "rawtypes", "unchecked" })
    public PageList selectPage(String channelSystemId, String responseCode, int pageSize,
                               int pageNum) throws DataAccessException {

        Map param = new HashMap();

        param.put("channelSystemId", channelSystemId);
        param.put("responseCode", responseCode);
        param.put("pageSize", new Integer(pageSize));
        param.put("pageNum", new Integer(pageNum));

        Paginator paginator = new Paginator();
        paginator.setItemsPerPage(pageSize);
        paginator.setPage(pageNum);

        paginator.setItems(((Integer) getSqlMapClientTemplate().queryForObject(
            "MS-OUT-RESPONSE-CODE-SELECT-COUNT-FOR-PAGING", param)).intValue());

        PageList pageList = new PageList();
        pageList.setPaginator(paginator);

        if (paginator.getBeginIndex() <= paginator.getItems()) {
            param.put("startRow", new Integer(paginator.getBeginIndex() == 0 ? 0 : paginator
                .getBeginIndex() - 1));
            param.put("endRow", new Integer(10));
            pageList.addAll(getSqlMapClientTemplate().queryForList(
                "MS-MESSAGE-PARAM-SELECT-FOR-PAGING", param));
        }

        return pageList;
    }

}